﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
using Ue.Extensions;

namespace Ue.Extensions
{
    /// <summary>
    /// TypeExtensions 的摘要说明
    /// </summary>
    [TestClass]
    public class TypeExtensionTests
    {
        private IDictionary<PropertyInfo, IList<FakeAttribute>> result;

        [TestInitialize]
        public void Initial()
        {
            Type type = typeof(FakeObject);

            result = type.GetProperties<FakeAttribute>();
        }

        [TestMethod]
        public void GetAttributeProperties()
        {
            Assert.AreEqual(3, result.Count);
        }

        [TestMethod]
        public void ValidateAttributeValue()
        {
            foreach (PropertyInfo proeprty in result.Keys)
            {
                if (proeprty.Name == "FirstName")
                {
                    Assert.AreEqual("lsw",result[proeprty][0].Key);
                }
            }
        }

        private class FakeObject
        {
            [Fake(Key="lsw")]
            public string FirstName { get; set; }

            [Fake(Key="web")]
            public string LastName { get; set; }

            [Fake(Key = "lsw")]
            public string Name { get; set; }

            public string NoAttribute { get; set; }
        }

        private class FakeAttribute : Attribute
        {
            public string Key { get; set; }

            public string Value { get; set; }
        }
    }
}
